﻿@using Tracking = Software41.Tracking.Model
@model Software41.Tracking.Model.ProcessTraceInfo
@{
    ViewBag.Title = "ProcessInfoDetails";
    
}

@section Header{

    <link href="@Url.Content("~/Content/dynatree/skin-vista/ui.dynatree.css")" rel="stylesheet" type="text/css" id="skinSheet"/>
}


@section Scripts{

    
    <script type="text/javascript">
        $(function () {

            madmin.init();

            //set our page as active
            $('a[data-target-page="page-search"]').parent().parent().addClass('active');

            $("#StepInfoDetails").dynatree({
                clickFolderMode: 0,
                onActivate: function (node) {
                    // Use <a> href and target attributes to load the content:
                    if (node.data.href) {
                        // Open target
                        //window.open(node.data.href, node.data.target);
                        // or open target in iframe
                        //                $("[name=contentFrame]").attr("src", node.data.href);
                        $("#popupWindow").load(node.data.href);
                        openPopup();
                    }
                }
            });

            $("#popupWindow").dialog({
                autoOpen: false,
                title: 'Title',
                width: 500,
                height: 'auto',
                modal: true
            });

            // make code pretty
            window.prettyPrint && prettyPrint();
        });

        function openPopup() {
            $("#popupWindow").dialog("open");
        }
        function updatePlaceholder(context) {
            // the HTML output of the partial view
            var html = context.get_data();

            // the DOM element representing the placeholder
            var placeholder = context.get_updateTarget();

            // use jQuery to update the placeholder. It will execute any JavaScript statements
            $(placeholder).html(html);

            // return false to prevent the automatic update of the placeholder
            return false;
        }

    </script>
}

<h2>ProcessInfoDetails</h2>
@using (Html.BeginForm())
{
    <fieldset>
        <legend>ProcessInfo Details</legend>
        <div id="ProcessInfoDetails">
            <table>
                <tbody>
                    <tr>
                        <td>Event Name:</td>
                        <td>@Html.DisplayFor(m => m.Name)</td>
                    </tr>
                    <tr>
                        <td>Activity ID:</td>
                        <td>@Html.DisplayFor(m => m.ActivityID)</td>
                    </tr>
                    <tr>
                        <td>Application:</td>
                        <td>@Html.DisplayFor(m => m.Application)</td>
                    </tr>
                    <tr>
                        <td>CreatedBy:</td>
                        <td>@Html.DisplayFor(m => m.UserName)</td>
                    </tr>
                    <tr>
                        <td>CreatedBy (UserId):</td>
                        <td>@Html.DisplayFor(m => m.UserId)</td>
                    </tr>
                    <tr>
                        <td>Begin:</td>
                        <td>@Model.Begin.Value.ToLocalTime()</td>
                    </tr>
                    <tr>
                        <td>End:</td>
                        <td>@(Model.End.HasValue == true ? Model.End.Value.ToLocalTime().ToString() : "")
                        </td>
                    </tr>
                    <tr>
                        <td>Duration:</td>
                        <td>@Html.DisplayFor(m => m.ProcessDuration)</td>
                    </tr>
                </tbody>
            </table>
        </div>
    </fieldset>
    
   
    <fieldset>
        <legend>Related Processes</legend>
        <ul>
            @if ((Model.RelatedProcesses != null) && (Model.RelatedProcesses.Count() > 0))
            {
                foreach (Tracking.ProcessTraceInfo rpi in Model.RelatedProcesses)
                {
                <li>@Html.ActionLink(rpi.Name, "ProcessInfoDetails", new { processInfoActivityId = rpi.ActivityID })
                </li>
                }
            }
        </ul>
    </fieldset>
    
    <fieldset>
        <legend>Steps</legend>
        <div id="StepInfoDetails">
            <ul id="treedata" style="display: none;">
                @foreach (Tracking.StepInfo si in Model.StepInfos)
                {
                    <li class="expanded folder" >
                        @Ajax.ActionLink(si.Name, "StepInfoDetails", new { stepInfoActivityId = si.ActivityID },
                                        new AjaxOptions
                                        {
                                            HttpMethod = "GET",
                                            UpdateTargetId = "popupWindow",
                                            InsertionMode = InsertionMode.Replace,
                                            OnComplete = "openPopup"
                                        })
                        <ul>
                            @foreach (Tracking.DocReferenceData refDoc in si.ReferenceData)
                            {
                                <li>
                                    @Ajax.ActionLink("RefDoc - " + refDoc.ReferenceName,
                                                                    "ReferenceDocumentDetails",
                                                                    refDoc,
                                                    new AjaxOptions
                                                    {
                                                        HttpMethod = "GET",
                                                        UpdateTargetId = "popupWindow",
                                                        InsertionMode = InsertionMode.Replace,
                                                        OnComplete = "openPopup"
                                                    })
                                </li>
                            }

                            @foreach (Tracking.ActionInfo ai in si.ActionInfos)
                            {
                                <li class="folder">
                                        @Ajax.ActionLink("Action - " + ai.Name, "ActionInfoDetails",
                                                    new { actionInfoActivityId = ai.ActivityID },
                                                    new AjaxOptions
                                                    {
                                                        HttpMethod = "GET",
                                                        UpdateTargetId = "popupWindow",
                                                        InsertionMode = InsertionMode.Replace,
                                                        OnComplete = "openPopup"
                                                    })
                                    <ul>
                                        @foreach (Tracking.DocReferenceData refDoc in ai.ReferenceData)
                                        {
                                            <li>@Ajax.ActionLink("RefDoc - " + refDoc.ReferenceName,
                                                                    "ReferenceDocumentDetails",
                                                                    refDoc,
                                                    new AjaxOptions
                                                    {
                                                        HttpMethod = "GET",
                                                        UpdateTargetId = "popupWindow",
                                                        InsertionMode = InsertionMode.Replace,
                                                        OnComplete = "openPopup"
                                                    })</li>
                                        }

                                        @if (ai.ExceptionDetail != null)
                                        {

                                            <li>
                                                @Ajax.ActionLink("ExceptionDetail - " + ai.ExceptionDetail.Message,
                                                                    "ExceptionDetail",
                                                    new AjaxOptions
                                                    {
                                                        HttpMethod = "GET",
                                                        UpdateTargetId = "popupWindow",
                                                        InsertionMode = InsertionMode.Replace,
                                                        OnComplete = "openPopup"
                                                    })
                                            </li>										
                                        }
                                    </ul>
                                </li>
                            }
                            @if (si.ExceptionDetail != null)
                            {
                                <li>
                                    @Ajax.ActionLink("ExceptionDetail - " + si.ExceptionDetail.Message,
                                                        "ExceptionDetail",
                                                            new { exceptionInfoActivityId = si.ExceptionDetail.ActivityID },
                                        new AjaxOptions
                                        {
                                            HttpMethod = "GET",
                                            UpdateTargetId = "popupWindow",
                                            InsertionMode = InsertionMode.Replace,
                                            OnComplete = "openPopup"
                                        })
                                </li>
                            }
                        </ul>
                    </li>
                }
            </ul>
        </div>


    </fieldset>@*
    <input type="submit" value="Return to Results" id="return" />
    *@
    <input type='button' onclick='javascript: history.go(-1); return false;' value="Return to Search Results" />
    <div id="popupWindow"></div>
}
